package com.szt.school.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szt.school.mapper.GoodsMapper2;
import com.szt.school.pojo.Goods;
import com.szt.school.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper2 goodsMapper2;
    @Override
    public List<Goods> findAll() {
        return goodsMapper2.selectAll();
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = {Exception.class})
    public PageInfo<Goods> getPageInfo(Integer curPage, Integer pageSize){
        PageHelper.startPage(curPage,pageSize);
        //查询
        List<Goods> goods = goodsMapper2.selectAll();
        return new PageInfo<>(goods);
    }
    @Override
    public Goods selectOne(Integer id) {
        return goodsMapper2.selectByPrimaryKey(id);
    }
}
